<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>06_天气</title>
    <script type="text/javascript" src="js/vue.js"></script>
</head>

<body>
    <div id="root">
        <h2>今天天气{{info}}</h2>
        <br>
        <button @click="change">切换天气</button>
    </div>
    <script type="text/javascript">
        var vm = new Vue({
            el: '#root',
            data: {
                isHot: true
            },
            computed: {
                info: function () {
                    return this.isHot ? '炎热' : '寒冷'
                }
            },
            methods: {
                change: function () {
                    this.isHot = !this.isHot;
                }
            },
            watch: {
                isHot: {
                    immediate: true,
                    handler(newval, oldval) {
                        console.log("值发生改变了", newval, oldval);
                    }
                }
            }
        });
    </script>
</body>

</html>